package monster.com.cvh.activity;

import android.content.Intent;
import android.os.Build;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;

import com.umeng.socialize.UMShareAPI;

import monster.com.cvh.R;
import monster.com.cvh.activity.base.PermissionActivity;
import monster.com.cvh.constant.Constans;
import monster.com.cvh.fragment.LoginFragment;

/**
 * 登陆界面
 */
public class LoginActivity extends PermissionActivity {

    private int mVisitorCode = -1;
    private static final String TAG = "LoginActivity";

    @Override
    protected int getContentViewResId() {
        //全屏显示
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        //适配刘海
        if (Build.VERSION.SDK_INT >= 28) {
            WindowManager.LayoutParams lp = getWindow().getAttributes();
            lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
            getWindow().setAttributes(lp);
        }
        return R.layout.activity_login;
    }

    @Override
    protected void initEvent() {
        initFragment();

    }

    @Override
    protected void initData() {
        Intent intent = getIntent();
        if (intent != null) {
            mVisitorCode = intent.getIntExtra(Constans.VISITOR, -1);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }

    private void initFragment() {
        FragmentManager fm = getSupportFragmentManager();
        LoginFragment loginFragment = null;
        if (mVisitorCode != -1) {
            loginFragment = LoginFragment.newIntance(mVisitorCode);
            Log.e(TAG, "游客调用了: ");
        } else {
            loginFragment = new LoginFragment();
            Log.e(TAG, "正常调用了: ");
        }
        FragmentTransaction transaction = fm.beginTransaction();
        transaction.setCustomAnimations(R.anim.slide_right_in, R.anim.slide_left_out);
        transaction.replace(R.id.cfl_content, loginFragment);
        transaction.commit();
    }
}
